#define _CRT_SECURE_NO_WARNINGS



//inline.cpp
//#include<iostream>
//using namespace std;
//
//inline double square(double x)
//{
//	return x * x;
//}
//
//int main()
//{
//	double a, b;
//	double c = 13.0;
//	a = square(5.0);
//	b = square(4.5 + 7.5);
//	cout << "a = " << a << ", b = " << b << "\n";
//	cout << "c = " << c;
//	cout << ", c squared = " << square(c++) << "\n";
//	cout << "Now c = " << c << "\n";
//
//	return 0;
//}



//firstref.cpp
//#include<iostream>
//using namespace std;
//int main()
//{
//	int rats = 101;
//	int& rodents = rats;
//	cout << "rats = " << rats << ", rodents = " << rodents << endl;
//	rodents++;
//	cout << "rats = " << rats << ", rodents = " << rodents << endl;
//	cout << "rats address = " << &rats << ", rodents address = " << &rodents << endl;
//
//	return 0;
//}



//secref.cpp
//#include<iostream>
//using namespace std;
//int main()
//{
//	int rats = 101;
//	int& rodents = rats;
//	cout << "rats = " << rats << ", rodents = " << rodents << endl;
//	cout << "rats address = " << &rats << ", rodents = " << &rodents << endl;
//	int bunnies = 50;
//	rodents = bunnies;
//	cout << "bunnies = " << bunnies << ", rats = " << rats << ", rodents = " << rodents << endl;
//	cout << "bunnies address = " << &bunnies << ", rodents address = " << &rodents << endl;
//
//	return 0;
//}



//swaps.cpp
//#include<iostream>
//using namespace std;
//
//void swapr(int& a, int& b);
//void swapp(int* a, int* b);
//void swapv(int a, int b);
//
//int main()
//{
//	int wallet1 = 300;
//	int wallet2 = 350;
//	cout << "wallet1 = $" << wallet1 << " wallet2 = $" << wallet2 << endl;
//
//	cout << "Using references to swap contents:\n";
//	swapr(wallet1, wallet2);
//	cout << "wallet1 = $" << wallet1 << " wallet2 = $" << wallet2 << endl;
//
//	cout << "Using pointer to swap contents:\n";
//	swapp(&wallet1, &wallet2);
//	cout << "wallet1 = $" << wallet1 << " wallet2 = $" << wallet2 << endl;
//
//	cout << "Trying to use passing by value:\n";
//	swapv(wallet1, wallet2);
//	cout << "wallet1 = $" << wallet1 << " wallet2 = $" << wallet2 << endl; 
//
//	return 0;
//}
//
//void swapr(int& a, int& b)
//{
//	int temp;
//	temp = a;
//	a = b;
//	b = temp;
//}
//
//void swapp(int* a, int* b)
//{
//	int temp;
//	temp = *a;
//	*a = *b;
//	*b = temp;
//}
//
//void swapv(int a, int b)
//{
//	int temp;
//	temp = a;
//	a = b;
//	b = temp;
//}



//cubes.cpp
//#include<iostream>
//double cube(double a);
//double recube(double& ra);
//
//int main()
//{
//	using namespace std;
//	double x = 3.0;
//
//	cout << cube(x);
//	cout << " = cube of " << x << endl;
//	cout << recube(x);
//	cout << " = cube of " << x << endl;
//
//	return 0;
//}
//
//double cube(double a)
//{
//	a *= a * a;
//	return a;
//}
//
//double recube(double& ra)
//{
//	ra *= ra * ra;
//	return ra;
//}



//strc_ref.cpp
//#include<iostream>
//#include<string>
//struct free_throws
//{
//	std::string name;
//	int made;
//	int attempts;
//	float percent;
//};
//
//void display(const free_throws& ft);
//void set_pc(free_throws& ft);
//free_throws& accumulate(free_throws& target,const free_throws& source);
//
//int main()
//{
//	free_throws one = { "Ifelsa Branch",13,14 };
//	free_throws two = { "Andor Knott",10,16 };
//	free_throws three = { "Minnie Max",7,9 };
//	free_throws four = { "Whily Looper",5,9 };
//	free_throws five = { "Long Long",6,14 };
//	free_throws team = { "Throwgoods",0,0 };
//	free_throws dup;
//
//	set_pc(one);
//	display(one);
//	accumulate(team, one);
//	display(team);
//	display(accumulate(team, two));
//	accumulate(accumulate(team, three), four);
//	display(team);
//
//	dup = accumulate(team, five);
//	std::cout << "Displaying team: ";
//	display(team);
//	std::cout << "Displaying dup after assignment: ";
//	display(dup);
//	set_pc(four);
//	accumulate(dup, five) = four;
//	std::cout << "Displaying dup after ill_advised assignment: ";
//	display(dup);
//
//	return 0;
//}
//
//void display(const free_throws& ft)
//{
//	using std::cout;
//	cout << "Name: " << ft.name << '\n';
//	cout << " Made: " << ft.made << '\t';
//	cout << "Attempts: " << ft.attempts << '\t';
//	cout << "Percent: " << ft.percent << '\n';
//}
//
//void set_pc(free_throws& ft)
//{
//	if (ft.attempts != 0)
//		ft.percent = 100.0f * float(ft.made) / float(ft.attempts);
//	else
//		ft.percent = 0;
//}
//
//free_throws& accumulate(free_throws& target, const free_throws& source)
//{
//	target.attempts += source.attempts;
//	target.made += source.made;
//	set_pc(target);
//	return target;
//}



//strquote.cpp
//#include<iostream>
//#include<string>
//
//using namespace std;
//
//string version1(const string& s1, const string& s2);
//const string& version2(string& s1, const string& s2);
//const string& version3(string& s1, const string& s2);
//
//int main()
//{
//	string input;
//	string copy;
//	string result;
//	
//	cout << "Enter a string:";
//	getline(cin, input);
//	copy = input;
//	cout << "Your string as entered: " << input << endl;
//	result = version1(input, "***");
//	cout << "Your string enhanced: " << result << endl;
//	cout << "Your original string: " << input << endl;
//
//	result = version2(input, "###");
//	cout << "Your string enhanced: " << result << endl;
//	cout << "Your original string: " << input << endl;
//
//	cout << "Resetting origina string.\n";
//	input = copy;
//	result = version3(input, "@@@");
//	cout << "Your string enhanced: " << result << endl;
//	cout << "Your original string: " << input << endl;
//
//	return 0;
//}
//
//string version1(const string& s1, const string& s2)
//{
//	string temp;
//	temp = s2 + s1 + s2;
//	return temp;
//}
//
//const string& version2(string& s1, const string& s2)
//{
//	s1 = s2 + s1 + s2;
//	return s1;
//}
//
//const string& version3(string& s1, const string& s2)
//{
//	string temp;
//	temp = s2 + s1 + s2;
//	return temp;
//}



//filefunc.cpp
//#include<iostream>
//#include<fstream>
//#include<cstdlib>
//using namespace std;
//
//void file_it(ostream& os, double fo,const double fe[], int n);
//const int LIMIT = 5;
//
//int main()
//{
//	ofstream fout;
//	const char* fn = "ep-date.txt";
//	fout.open(fn);
//	if (!fout.is_open())
//	{
//		cout << "Can't open " << fn << ". Bye\n";
//		exit(EXIT_FAILURE);
//	}
//	double objective;
//	cout << "Enter the focal length of your telephone objective in mm: ";
//	cin >> objective;
//	double eps[LIMIT];
//	cout << "Enterthe focal lengths, in mm, of " << LIMIT << "eyepieces:\n";
//	for (int i = 0; i < LIMIT; i++)
//	{
//		cout << "Eyepiece #" << i + 1 << ": ";
//		cin >> eps[i];
//	}
//	file_it(fout, objective, eps, LIMIT);
//	file_it(cout, objective, eps, LIMIT);
//	cout << "Done.\n";
//
//	return 0;
//}
//
//void file_it(ostream& os, double fo, const double fe[], int n)
//{
//	ios_base::fmtflags initial;
//	initial = os.setf(ios_base::fixed);
//	os.precision(0);
//	os << "Focal length of objective: " << fo << "mm\n";
//	os.setf(ios::showpoint);
//	os.precision(1);
//	os.width(12);
//	os << "f.1. eyepiece";
//	os.width(15);
//	os << "magnification" << endl;
//	for (int i = 0; i < n; i++)
//	{
//		os.width(12);
//		os << fe[i];
//		os.width(15);
//		os << int(fo / fe[i] + 0.5) << endl;
//	}
//	os.setf(initial);
//}



//left.cpp
//#include<iostream>
//using namespace std;
//const int ArSize = 80;
//char* left(const char* str, int n = 1);
//int main()
//{
//	char sample[ArSize];
//	cout << "Enter a string:\n";
//	cin.getline(sample, ArSize);
//	char* ps = left(sample, 4);
//	cout << ps << endl;
//	delete[]ps;
//	ps = left(sample);
//	cout << ps << endl;
//	delete[]ps;
//
//	return 0;
//}
//char* left(const char* str, int n)
//{
//	if (n < 0)
//		n = 0;
//	char* p = new char[n + 1];
//	int i = 0;
//	for (i = 0; i < n && str[i]; i++)
//	p[i] = str[i];
//	while (i <= n)
//		p[i++] = '\0';
//	return p;
//}



//leftover.cpp
//#include<iostream>
//using namespace std;
//
//unsigned long left(unsigned long num, unsigned ct);
//char* left(const char* str, int n = 1);
//
//int main()
//{
//	const char* trip = "Hawaii!!";
//	unsigned long n = 1234578;
//	int i;
//	char* temp;
//
//	for (i = 1; i < 10; i++)
//	{
//		cout << left(n, i) << endl;
//		temp = left(trip, i);
//		cout << temp << endl;
//		delete[]temp;
//	}
//
//	return 0;
//}
//
//char* left(const char* str, int n)
//{
//	if (n < 0)
//		n = 0;
//	char* p = new char[n + 1];
//	int i = 0;
//	for (i = 0; i < n && str[i]; i++)
//		p[i] = str[i];
//	while (i <= n)
//		p[i++] = '\0';
//	return p;
//}
//
//unsigned long left(unsigned long num, unsigned ct)
//{
//	unsigned digit = 1;
//	unsigned long n = num;
//
//	if (num == 0 || ct == 0)
//		return 0;
//	while (n /= 10)
//		digit++;
//	if (digit > ct)
//	{
//		ct = digit - ct;
//		while (ct--)
//			num /= 10;
//		return num;
//	}
//	else
//		return num;
//}



//funtemp.cpp
//#include<iostream>
//using namespace std;
//
//struct job
//{
//	char name[40];
//	double salary;
//	int floor;
//};
//
//template<typename T>
//void Swap(T& a, T& b);
//
//template<typename T>
//void Swap(T* a, T* b, int n);
//const int Lim = 8;
//void Show(int a[]);
//
//template<> void Swap<job>(job& j1, job& j2);
//void Show(job& j);
//
//int main()
//{
//	int i = 10;
//	int j = 20;
//	cout << "i, j = " << i << " ," << j << ".\n";
//	cout << "Using complier_generated int swapper:\n";
//	Swap(i, j);
//	cout << "Now i, j = " << i << " ," << j << ".\n";
//
//	double x = 24.5;
//	double y = 81.7;
//	cout << "x, y = " << x << " ," << y << ".\n";
//	cout << "Using complier_generated int swapper:\n";
//	Swap(x, y);
//	cout << "Now x, y = " << x << " ," << y << ".\n";
//
//	cout << "\n\n\n\n" << "Function overloading:\n";
//	int d1[Lim] = { 0,7,0,4,1,7,7,6 };
//	int d2[Lim] = { 0,7,2,0,1,9,6,9 };
//	cout << "Original arrays\n";
//	Show(d1);
//	Show(d2);
//	Swap(d1, d2, Lim);
//	cout << "Swapped arrays:\n";
//	Show(d1);
//	Show(d2);
//
//	cout << "\n\n\n\n" << "Explicit materialization:\n";
//	job sue = { "Susan Yaffee", 73000.60, 7 };
//	job sidney = { "Sidney Taffee", 78060.72, 9 };
//	cout << "Before job swapping:\n";
//	Show(sue);
//	Show(sidney);
//	Swap(sue, sidney);
//	cout << "After job swapping:\n";
//	Show(sue);
//	Show(sidney);
// 
//	return 0;
//}
//
//template<typename T>
//void Swap(T& a, T& b)
//{
//	T temp;
//	temp = a;
//	a = b;
//	b = temp;
//}
//
//template<typename T>
//void Swap(T* a, T* b, int n)
//{
//	T temp;
//	for (int i = 0; i < n; i++)
//	{
//		temp = a[i];
//		a[i] = b[i];
//		b[i] = temp;
//	}
//}
//
//void Show(int a[])
//{
//	cout << a[0] << a[1] << "/";
//	cout << a[2] << a[3] << "/";
//	for (int i = 4; i < Lim; i++)
//		cout << a[i];
//	cout << endl;
//}
//
//template<>void Swap<job>(job& j1, job& j2)
//{
//	double t1;
//	int t2;
//	t1 = j1.salary;
//	j1.salary = j2.salary;
//	j2.salary = t1;
//	t2 = j1.floor;
//	j1.floor = j2.floor;
//	j2.floor = t2;
//}
//
//void Show(job& j)
//{
//	cout << j.name << ": $" << j.salary;
//	cout << " on floor " << j.floor << endl;
//}



//tempover.cpp
//#include<iostream>
//using namespace std;
//
//template<typename T>
//void showarray(T arr[], int n);
//
//template<typename T>
//void showarray(T* arr[], int n);
//
//struct debts
//{
//	char name[50];
//	double amount;
//};
//
//int main()
//{
//	int things[6] = {13,31,103,301,310,130};
//	struct debts mr_e[3] =
//	{
//		{"Ima Wolfa", 2400.0},
//		{"Ura Foxe", 1300.0},
//		{"Iby Stout", 1800.0}
//	};
//	double* pd[3];
//
//	for (int i = 0; i < 3; i++)
//		pd[i] = &mr_e[i].amount;
//
//	cout << "Listing Mr.E's counts of things:\n";
//	showarray(things, 6);
//	cout << "Listing Mr.E's debts:\n";
//	showarray(pd, 3);
//
//	return 0;
//}
//
//template<typename T>
//void showarray(T arr[], int n)
//{
//	cout << "Template A\n";
//	for (int i = 0; i < n; i++)
//	{
//		cout << arr[i] << " ";
//	}
//	cout << endl;
//}
//
//template<typename T>
//void showarray(T* arr[], int n)
//{
//	cout << "Template B\n";
//	for (int i = 0; i < n; i++)
//	{
//		cout << *arr[i] << " ";
//	}
//	cout << endl;
//}



//choices.cpp
//#include<iostream>
//using namespace std;
//template<typename T>
//T lesser(T a, T b)
//{
//	return a < b ? a : b;
//}
//
//int lesser(int a, int b)
//{
//	a = a < 0 ? -a : a;
//	b = b < 0 ? -b : b;
//	return a < b ? a : b;
//}
//
//int main()
//{
//	int m = 20;
//	int n = -30;
//	double x = 15.5;
//	double y = 25.9;
//
//	cout << lesser(m, n) << endl;
//	cout << lesser(x, y) << endl;
//	cout << lesser<>(m , n) << endl;
//	cout << lesser<int>(x, y) << endl;
//
//	return 0;
//}